package com.propic.www;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.Scene;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;

import java.awt.*;
import java.io.IOException;
import java.net.URI;


/**
 * Created by geange on 16-4-27.
 */
public class Openbrowse extends Application{
    public Stage openbrowser(String url){
        URI inuri = URI.create(url);

        WebView webView = new WebView();
        WebEngine engine = webView.getEngine();
        engine.load("https://git.oschina.net/geange_code/JavafxImage");
        engine.locationProperty().addListener(new ChangeListener<String>() {
            @Override
            public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
                if(!newValue.contains("git.oschina.net")){
                    Platform.runLater(new Runnable() {
                        @Override
                        public void run() {
                            engine.load(oldValue);
                        }
                    });
                }
            }
        });

//        Desktop dp = Desktop.getDesktop();
//        if (dp.isSupported(Desktop.Action.BROWSE)){
//            try {
//                dp.browse(inuri);
//            } catch (IOException e) {
//                e.printStackTrace();
//            }
//        }

        Stage stage = new Stage();
        Scene scene = new Scene(webView, 1100, 680);
        stage.setScene(scene);
        return stage;
    }

    public static void main(String[] args){
//        System.loadLibrary();
        launch();
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        Stage stage = new Openbrowse().openbrowser("");
        stage.show();
    }
}
